home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / FILLAREA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.5 KB  |  50 lines

  1. /*  fillarea.c - fill sort area with records */
  2. #include   "stdio.h"
  3. #include   "sorttext.h"
  4.  
  5. int  rsize ;            /* size of record found */
  6. char rarea[ MAX_RSIZE ] ;    /* storage for one record */
  7.  
  8. int  fillarea(area,asize,p,psize,pnp,infile)
  9.   char    area[] ;        /* address of storage area for strings */
  10.   int    asize ;         /* size of area */
  11.   char    *p[] ;            /* storage pointers to records here */
  12.   int    psize ;         /* size of p[] - ( max. no. records ) */
  13.   int    *pnp ;            /* store no. of records at this loc. */
  14.   FILE    *infile ;        /* input file */
  15.   {
  16.      int   nrec  ;        /* counter for number of records found */
  17.      unsigned start ;        /* index of first free byte in area[] */
  18.  
  19.      start = 0 ;        /* free space at area[0] */
  20.      nrec  = 0 ;        /* no records yet */
  21.  
  22.      while( rsize > 0 )     /* stop at enf-of-file */
  23.     {            /* check for room  */
  24.        if( ( (start+rsize) > asize ) || ( nrec >= psize ) )
  25.           {  *pnp = nrec ;
  26.          return( NOT_EOF ) ;
  27.           }
  28.                 /* copy record to storage area */
  29.        movedata( & area[start] , rarea,rsize) ;
  30.  
  31.        p[nrec] = & area[start] ;    /* store pointer to record */
  32.        nrec = nrec + 1 ;        /* count it */
  33.        start = start + rsize  ;    /* move start past this record */
  34.                     /* get next record */
  35.        rsize = getrec(rarea,MAX_RSIZE,infile) ;
  36.     } ;
  37.      *pnp = nrec ;
  38.      return( AT_EOF ) ;
  39.   }
  40.  
  41.  
  42. initfill(infile)    /* called first time to read first record */
  43.   FILE    *infile ;
  44.   {
  45.      rsize = getrec(rarea,MAX_RSIZE,infile) ;
  46.   }
  47.  
  48.  
  49.  
  50.